package com.example.smartall.diaglog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartall.R;

/**
 * 修改用户信息弹窗
 * 负责将输入的字段用回调返回给调用的ListView
 */
public class ChangInfoDialog extends Dialog {
    private EditText etChange;
    private Button cancel;
    private Button ok;
    private OnWhichClickListener listener;

    public void setListener(OnWhichClickListener listener) {
        this.listener = listener;
    }

    public ChangInfoDialog(@NonNull Context context) {
        super(context);
    }

    public ChangInfoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected ChangInfoDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chage_info_dialog);

        etChange = (EditText) findViewById(R.id.et_change);
        cancel = (Button) findViewById(R.id.cancel);
        ok = (Button) findViewById(R.id.ok);

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //回调
                if (listener != null){
                    listener.onOkClick(etChange.getText().toString());
                }
                dismiss();
            }
        });
    }

    public interface OnWhichClickListener{
        void onOkClick(String s);
    }
}
